package me.zk.practice1.hw;

import java.util.Scanner;

public class HWBJJ10 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] map = new int[300][300];
        int line = 0;
        while (scanner.hasNext()) {
            String s = scanner.nextLine();
            if (s.equals("1")) {
                break;
            }
            for (int i = 0; i < s.length(); i++) {
                map[line][i] = Integer.parseInt(String.valueOf(s.charAt(i)));
            }
            line++;
        }
        int result = 0;
        for (int i = 0; i < 300; i++) {
            for (int j = 0; j < 300; j++) {
                result = Math.max(result,get(i,j,0,map));
            }
        }
        System.out.println(result);
    }

    public static  int get(int x,int y,int result, int[][] map) {
        if (map[x][y] == 0) {
            return result;
        }
        result+= map[x][y];
        map[x][y]=0;
        if (can(x-1,y,map)) {
            result = get(x-1,y,result,map);
        }
        if (can(x+1,y,map)) {
            result = get(x+1,y,result,map);
        }
        if (can(x,y-1,map)) {
            result = get(x,y-1,result,map);
        }
        if (can(x,y+1,map)) {
            result = get(x,y+1,result,map);
        }
        return result;
    }

    public static boolean can(int x,int y, int[][] map) {
        if (x<0||x>=300) {
            return false;
        }
        if (y < 0||y>=300){
            return false;
        }
        return map[x][y]>0;
    }
}
